import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;
/**
 * Write a description of class fuego here.
 * 
 * @author Jesús Aurelio Hrnández AguilarAndrés Cruz Santiago
 * @version 01/06/13
 */
public class Fuego extends Actor
{
    private int direccion;
    //private GreenfootImage ima;
    /**
     * Constructor de Actor
     * @param unaDireccion es la Dirección del Fuego
     */
    public Fuego(int unaDireccion)
    {
        direccion=unaDireccion;
    }

    /**
     * Act - do whatever the fuego wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        this.mueve();
        this.eliminaFuego();
    }    

    public void eliminaFuego()
    {
        World world=getWorld();
        List l=null;
        l=getIntersectingObjects(Actor.class);
        if( l!=null && !(l.get(0) instanceof Fuego))
        {
            if (this.getX()==0 || this.getX()==world.getWidth()-1 || l!=null)
                world.removeObject(this);
            else
            if (this.getY()==0 || this.getY()==world.getHeight()-1 || l!=null)
                world.removeObject(this);
        }
    }

    public void mueve()
    {
        switch(direccion)
        {

            case 0:
            this.setLocation(this.getX(), this.getY()-1);
            break;
            case 1: 
            this.setLocation(this.getX(), this.getY()+1);
            break;
            case 2: 
            this.setLocation(this.getX()+1, this.getY());
            break;
            case 3:
            this.setLocation(this.getX()-1, this.getY());
            break;
        }
    }
}
